package com.maimao.search.controller;

import com.maimao.core.model.resp.Result;
import com.maimao.model.search.DocInput;
import com.maimao.search.service.DocService;
import com.maimao.search.service.IndexService;
import com.sun.tools.internal.xjc.reader.xmlschema.BindGreen;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author MaoLin Wang
 * @date 2021/1/3 8:20 下午
 */
@RestController
@RequestMapping("/search/doc")
public class DocController {
    @Autowired
    private DocService docService;

    @Autowired
    private IndexService indexService;

    @PostMapping("/create")
    public Result<?> createDoc(@RequestBody DocInput docInput) {
        if (docInput == null || StringUtils.isAnyEmpty(docInput.getIndex(), docInput.getJsonSource(), docInput.getType())) {
            return Result.notValid();
        }
        docService.createDoc(docInput.getIndex(), docInput.getId(), docInput.getJsonSource(), docInput.getType());
        return Result.ok();
    }

    @GetMapping("/createIndex")
    public Result<?> createIndex() {
        indexService.createGoodsCheckIndex();
        return Result.ok();
    }
}
